<template>
  <div class="swipe">
    <div class="swiper-container" ref="swiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item,index) in data" :key="index">
          <img :src="item" alt="banner">
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>

<script>
  import Swiper from 'swiper/swiper-bundle.js'
  import 'swiper/swiper-bundle.min.css'

  export default {
    name: "banner-list",
    props: {
      data: Array
    },
    watch: {
      data() {
        this.$nextTick(() => {
          new Swiper(this.$refs.swiper, {
            loop: true, // 循环模式选项
            autoplay: {
              delay: 3000,
              //循环一轮后继续轮播
              disableOnInteraction:false
            },
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination',
            }
          })
        })
      }

    }
  }
</script>

<style lang="scss" scoped>
  @import "../../assets/global-style";

  .swipe {
    width: 100%;
    height: 160px;
    position: relative;

    &::before {
      content: '';
      display: block;
      width: 100%;
      height: 65%;
      background: $theme-color;
    }

    .swiper-container {
      width: 98%;
      height: 160px;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%);
      overflow: hidden;
      img {
        width: 100%;
        border-radius: 7px;
      }
    }
  }
</style>

<style lang="scss">
  @import "../../assets/global-style";
  .swiper-pagination-bullet-active{
    background: $theme-color;
  }
  .swiper-pagination-bullet {
    width: 8px;
    height: 8px;
  }
  .swiper-container-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet {
    margin: 0 4px;
  }
</style>